<?php
/**
 *
 * 版权所有：安德玛(underArmour)
 * 作    者：1554324405@qq.com
 * 日    期：2020-05-20
 * 版    本：1.0.0
 * 功能说明：首页控制器。
 *
 **/
namespace Api\Controller;

class IndexController extends ComController
{   
    /**
     * 轮播图列表
     */
    public function bannerList()
    {
        if(!IS_GET){
            $this->res['code'] = 100;
            $this->res['msg'] = '请使用GET请求方式';
            $this->response($this->res,'json');
        }
        $list = M('banner')->order('o asc')->field('pic,url')->select();
        foreach ($list as $k=>&$v){
            $list[$k]['pic'] = C('URL').$v['pic'];
            if(!$v['url']){
                $list[$k]['url'] = "";
            }
        }
        //未读消息数量
        $whereMessage['uid'] = array('in',$this->user['id'].',0');
        $notIdArr = M('user_readmessage')->where(array('uid'=>$this->user['id']))->field('msg_id')->select();
        if($notIdArr){
            $notIds = '';
            foreach($notIdArr as $key=>$vals){
                $notIds.=$vals['msg_id'].',';
            }
            $notIds = rtrim($notIds, ',');
            $whereMessage['id'] = array('not in',$notIds);
        }
        $count = M('user_message')->where($whereMessage)->count();
        $this->res['msg'] = 'success';
        $this->res['data'] = $list;
        $this->res['noread_notice_num'] = $count;
        $this->response($this->res, 'json');
    }
    
    /**
     * 会员动态
     */
    public function userDynamic()
    {
        if(!IS_GET){
            $this->res['code'] = 100;
            $this->res['msg'] = '请使用GET请求方式';
            $this->response($this->res,'json');
        }
        $list = M('user_dynamic')->order('t desc')->limit(100)->select();
        foreach ($list as $k=>&$v){
            $list[$k]['t'] = date('m-d H:i',$v['t']);
            $list[$k]['mobile'] = yc_phone($v['mobile']);
        }
        $this->res['msg'] = 'success';
        $this->res['data'] = $list;
        $this->response($this->res, 'json');
    }
    
}